package org.webdb.webapp.injectors;

import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.spi.StringConverter;
import org.webdb.core.database.DataBase;
import org.webdb.core.database.DataBaseRegistry;

@Provider
public class DataBaseStringInjector implements StringConverter<DataBase> {

    private DataBaseRegistry registry;

    public DataBaseStringInjector(DataBaseRegistry registry) {
        this.registry = registry;
    }

    @Override
    public DataBase fromString(String databaseName) {
        return registry.get(databaseName);
    }

    @Override
    public String toString(DataBase database) {
        return database.getName();
    }

}
